package Vista;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToolBar;


@SuppressWarnings("serial")
public class MainPanel extends JPanel {
	private JToolBar toolbar;
	private JButton altaClienteB, altaVehiculoB, altaSucursalB, altaRutaB;
	
	private AltaVehiculo vehiculoPanel;
	private ClientePanel clientePanel;
	private AltaSucursal sucursalPanel;
	private AltaRuta rutaPanel;
	
	public static void main(String[] args) {
		MainPanel mainPanel = new MainPanel();
		mainPanel.showPanel();
	}
	
	public MainPanel() {
		initGui();
		layoutComponents();
		initActions();
	}
	
	private void initGui() {
		vehiculoPanel = new AltaVehiculo();
		clientePanel = new ClientePanel();
		sucursalPanel = new AltaSucursal();
		rutaPanel = new AltaRuta();
		altaClienteB = new JButton();
		altaVehiculoB = new JButton();
		altaSucursalB = new JButton();
		altaRutaB = new JButton();
	}

	private void layoutComponents() {
		this.setLayout(new BorderLayout());
        
        setPreferredSize(new Dimension(450, 130));
        toolbar = new JToolBar();
        add(toolbar, BorderLayout.PAGE_START);
        
        toolbar.add(altaClienteB);
        toolbar.add(altaVehiculoB);
        toolbar.add(altaSucursalB);
        toolbar.add(altaRutaB);
	}
	
	private void initActions() {
		altaClienteB.setAction(new AbstractAction("Nuevo Cliente"){
			@Override
			public void actionPerformed(ActionEvent e) {
				clientePanel.showPanel();
			}			
		});
		
		altaVehiculoB.setAction(new AbstractAction("Nuevo Vehiculo"){
			@Override
			public void actionPerformed(ActionEvent e) {
				vehiculoPanel.showPanel();
			}			
		});
		
		altaSucursalB.setAction(new AbstractAction("Nueva Sucursal"){
			@Override
			public void actionPerformed(ActionEvent e) {
				sucursalPanel.showPanel();
			}			
		});
		altaRutaB.setAction(new AbstractAction("Nueva Ruta"){
			@Override
			public void actionPerformed(ActionEvent e) {
				rutaPanel = new AltaRuta();
				rutaPanel.showPanel();
			}			
		});
	
	}
	
	public void showPanel() {
		final JFrame mainFrame = new JFrame();
        mainFrame.setTitle("Aplicaciones Distribuidas");
        mainFrame.getContentPane().add(this);
        mainFrame.setPreferredSize(new Dimension(710,340));
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.pack();
        mainFrame.setLocationRelativeTo(null);
        mainFrame.setVisible(true);
	}
}
